package org.xxforest.game.notsing.screen.tmx;

import org.xxforest.game.core.XX;
import org.xxforest.game.core.scenes.scene2d.XXScreen;
import org.xxforest.game.core.scenes.scene2d.events.XXKeyCode;
import org.xxforest.game.core.scenes.scene2d.events.listeners.XXKeyPressListener;
import org.xxforest.game.core.scenes.scene2d.events.listeners.XXTouchListener;
import org.xxforest.game.core.scenes.scene2d.events.type.XXKeyPressEvent;
import org.xxforest.game.core.scenes.scene2d.events.type.XXTouchEvent;
import org.xxforest.game.core.scenes.scene2d.graphics.XXTiledMap;
import org.xxforest.game.core.scenes.scene2d.selector.XXScheduleSelector;
import org.xxforest.game.core.scenes.scene2d.ui.XXLable;
import org.xxforest.game.notsing.screen.rpg.layers.FloatLayer;

import com.badlogic.gdx.Gdx;

public class TmxScreen extends XXScreen{

	private XXTiledMap tiledMap ;
	
	@Override
	public void onCreate() {
		tiledMap = XXTiledMap.create("map/m.tmx","map/");
		this.add(tiledMap);
		
		this.focusMe() ;
		this.setKeyPressEvent(new XXKeyPressListener() {
			
			@Override
			public boolean handle(XXKeyPressEvent event) {
				if(event.isPress(XXKeyCode.VK_UP)){
					XX.director.getCamera().position.y += 10 ;
				}
				if(event.isPress(XXKeyCode.VK_DOWN)){
					XX.director.getCamera().position.y -= 10 ;
				}
				if(event.isPress(XXKeyCode.VK_LEFT)){
					XX.director.getCamera().position.x -= 10 ;
				}
				if(event.isPress(XXKeyCode.VK_RIGHT)){
					XX.director.getCamera().position.x += 10 ;
				}
				return false;
			}
		});
		
		FloatLayer floatLayer = new FloatLayer(getWidth(), getHeight());
		
		final XXLable lable = XXLable.create("FPS:0");
		lable.setPosition(0,XX.data.getGraphicHeight());
		
		floatLayer.add(lable);
		
		this.addSelector(new XXScheduleSelector() {
			@Override
			public void run() {
				lable.setText("FPS:"+Gdx.graphics.getFramesPerSecond());
			}
		}, 0.2f);
		
		this.add(floatLayer);
		
		//测试获得地图参数
		System.out.println(tiledMap.getTileProperty(1, 344, 2837, "aa"));
		
		this.touchAble() ;
		this.setClickDownEvent(new XXTouchListener() {
			
			@Override
			public boolean handle(XXTouchEvent event) {
				System.out.println(event.getPoint());
				return false;
			}
		});
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void resume() {
		
	}

	@Override
	public void show() {
		
	}

	@Override
	public void hide() {
		
	}

}
